<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 400px;
            margin-bottom: 30px;
            border: 1px solid red;
        }
        
        .son {
            width: 0px;
            height: 40px;
            background-color: palegreen;
            line-height: 40px;
            text-align: center;
        }
    </style>
</head>

<body>
    <div class="box">
        <div class="son">
            <span>0</span><span>%</span>
        </div>
    </div>
    <button id="btn">安装</button>
    <script>
        // 利用定时器来进行递增操作（width、百分数），当变量达到400px时停止定时器
        let btn = document.getElementById("btn")
        let div = document.getElementsByTagName("div")
        let span = document.getElementsByTagName("span")
        let timer = null
        btn.onclick = function() {
            let num = 0
            if (timer == null) {
                let timer = setInterval(() => {
                    num += 1
                        // 给宽进行递增
                    div[1].style.width = num + "px"
                        // 给百分比递增
                    span[0].innerText = Math.ceil(num / 400 * 100)
                    if (num == 400) {
                        clearInterval(timer)
                    }
                }, 10)
            }
        }
    </script>
</body>

</html>